package com.ocom.oauth.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;

@Configuration
public class CaptchaConfig {

////    @Autowired
////    StringRedisTemplate redisTemplate;
//
////    @Bean(name = "AjCaptchaCacheService")
////    @Primary
//    @Primary
//    @Bean(name = "AjCaptchaCacheService")
//    public CaptchaCacheService captchaCacheService(AjCaptchaProperties config){
//        //缓存类型redis/local/....
////        CaptchaCacheService ret = CaptchaServiceFactory.getCache(config.getCacheType().name());
////        if(ret instanceof CaptchaCacheServiceRedisImpl){
////            ((CaptchaCacheServiceRedisImpl)ret).setStringRedisTemplate(redisTemplate);
////        }
////        return ret;
//        return new CaptchaCacheServiceRedisImpl();
//    }

    @Bean
    @ConditionalOnMissingBean
    public MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasenames("messages/messages","captcha/messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

}
